local msgproxy = require "msgproxy"
local tabletool = require "tabletool"
local json = require "cjson"
local dblog = require "dblog"
json.encode_sparse_array(true,1,1)
local GameLog = {}
----金币日志
----金币日志 key = tableid+roomsvrd_id+gameid+time+skynet.self()
---- 充值时key = 订单id  邮件 key = mail_key
-----rid 玩家rid, num 改变量, beforetotal 改变前数量  aftertotal 改变后数量
function GameLog.write_player_coinlog(rid, reason, key, num, beforetotal, aftertotal)
	local data = {
		rid=rid,
		reason=reason,
		key=key,
		num=num,
		beforetotal=beforetotal,
		aftertotal=aftertotal,
	}
	dblog.dblog_write("coinlog",data)
end

----宝石日志 key = tableid+roomsvrd_id+time+skynet.self()
---- 充值时key = 订单id  邮件 key = mail_key
-----rid 玩家rid，num 改变量, beforetotal 改变前数量  aftertotal 改变后数量
function GameLog.write_player_gemstonelog(rid, reason, key, num, beforetotal, aftertotal)
	local data = {
		rid=rid,
		reason=reason,
		key=key,
		num=num,
		beforetotal=beforetotal,
		aftertotal=aftertotal,
	}
	dblog.dblog_write("gemstonelog",data)
end

----房卡日志 key = tableid+roomsvrd_id+time+skynet.self()
---- 充值时key = 订单id  邮件 key = mail_key
-----rid 玩家rid，num 改变量, beforetotal 改变前数量  aftertotal 改变后数量
function GameLog.write_player_roomcardlog(rid, reason, key, num, beforetotal, aftertotal)
	local data = {
		rid=rid,
		reason=reason,
		key=key,
		num=num,
		beforetotal=beforetotal,
		aftertotal=aftertotal,
	}
	dblog.dblog_write("roomcardlog",data)
end

----奖券日志 key = tableid+roomsvrd_id+time+skynet.self()
---- 充值时key = 订单id  邮件 key = mail_key
-----rid 玩家rid，num 改变量, beforetotal 改变前数量  aftertotal 改变后数量
function GameLog.write_player_lotterylog(rid, reason, key, num, beforetotal, aftertotal)
	local data = {
		rid=rid,
		reason=reason,
		key=key,
		num=num,
		beforetotal=beforetotal,
		aftertotal=aftertotal,
	}
	dblog.dblog_write("lotterylog",data)
end

--isreg 1 表示新注册， 0 表示已经注册账号
function GameLog.write_player_loginlog(isreg, uid, rid, gameid, regfrom, platform, channel, authtype, version, logintime)
	local data = {
		uid = uid,
		rid = rid,
		gameid = gameid,
		regfrom = regfrom,
		platform = platform,
		channel = channel,
		authtype = authtype,
		isreg = isreg,
		version = version,
		actiontype = "login",
		logintime = logintime,
	}
	dblog.dblog_write("loginlog",data)
end

--战绩mongo记录
function GameLog.write_table_records(id, table_id, gameid, room_type, game_type, create_user_rid, create_time, create_user_rolename, create_user_logo, create_table_id, playerrecordlist)
	local data = {
		id = id,
		table_id = table_id,
		gameid = gameid,
		room_type = room_type,
		game_type = game_type,
		create_user_rid = create_user_rid,
		create_time = create_time,
		create_user_rolename = create_user_rolename,
		create_user_logo = create_user_logo,
		create_table_id = create_table_id,
		playerrecordlist = json.encode(playerrecordlist),
	}
	dblog.dblog_write("recordlog",data)
end

--[[
记录ios发货请求(state 1表示记录,2表示提交失败,3表示提交成功,4表示签名验证失败)
isbatch 表示是否是补单
]]
function GameLog.write_ios_deliverreqlog(rid, pay_type, good_id, ios_pay_order, option_data, state, isbatch)
	local data = {
		rid = rid,
		pay_type = pay_type,
		good_id = good_id,
		ios_pay_order = ios_pay_order,
		option_data = option_data,
		state = state,
		isbatch = isbatch,
	}
	dblog.dblog_write("iosdeliverreqlog", data)
end

--[[
充值订单状态流水
]]
function GameLog.write_orderlog(order)
	local data = order
	dblog.dblog_write("orderlog", data)
end

--- 领取邮件附件流水日志
-- @param rid
--
function GameLog.write_getmailitem_log(rid,gettime, mail_key, create_time, reason, mailcontent)
	local data = {
		rid = rid,
		mail_key = mail_key,
		create_time = create_time,
		reason = reason,
		gettime = gettime,
		mailcontent = mailcontent,
	}
	dblog.dblog_write("getmailitemlog",data)
end

function GameLog.write_givegemstone_log(data)
	dblog.dblog_write("givegemstonelog",data)	
end


return GameLog